package com.guigu.aws.demo01;

import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;

/**
 * Hello world!
 *
 */
public class S3FileListApp {

	private static String AWS_ACCESS_KEY = "AWS_ACCESS_KEY";
	private static String AWS_SECRET_KEY = "AWS_SECRET_KEY ";

//  列出桶中所有对象，并且看到文件夹中的文件
	public static void main(String[] args) {
		// 创建 s3 对象
		AmazonS3 s3 = new AmazonS3Client(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY));
		// 设置区域 ( 我们使用的是宁夏区域 )
		s3.setRegion(Region.getRegion(Regions.CN_NORTHWEST_1));
		// 文件夹名字 ：
		ObjectListing objects = s3.listObjects("demo02");
		do {
			for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
				System.out.println("Object: " + objectSummary.getKey());
			}
			objects = s3.listNextBatchOfObjects(objects);
		} while (objects.isTruncated());
	}

}
